package com.haozhen.sortnumber;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 实现map阶段任务
 *  思路是利用
 */
public class SortNumberMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取数据 转换为 数值型
       Integer num =  Integer.parseInt(value.toString());
       //将 数值型的数据做为key    主要考虑到 IntWritable 在shuffle中会默认按升序排列
       context.write(new IntWritable(num), NullWritable.get());
    }
}
